package com.F04.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.F04.dao.F0407Dao;
import com.F04.actionForm.F0407ActionForm;
import com.action.BaseAction;
import com.config.Constants;
import com.exception.SelectException;
import com.util.SessionUtils;

/**
 * �û��޸��������
 * 
 * @file F0407Action.java
 * @author wangjn
 * @since 2009-2-13
 * @version 1.0
 */

public class F0407Action extends BaseAction {

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		F0407ActionForm actionForm = (F0407ActionForm) form;
		F0407Dao dao = new F0407Dao();
		String operationType = actionForm.getOperationType();
		String language = SessionUtils.getLocale(request);
		actionForm.setLanguage(language);
		try {
//			查询
			if (Constants.QUERYLIST.equals(operationType)) {

				List list[] = (dao.select(actionForm));
				if(list == null){
					List rtnList = new ArrayList();
					actionForm.setList(rtnList);
					actionForm.setWeekList(null);
					return mapping.findForward(Constants.List);
				}
				actionForm.setWeekList(list[0]);
				actionForm.setList(list[1]);
				return mapping.findForward(Constants.List);

			}
//			初始化
			if (Constants.INIT.equals(operationType)) {
				this.doINIT(actionForm);
				return mapping.findForward(Constants.List);
			}
			
//			返回
			if(Constants.BACK.equals(operationType)){
				return mapping.findForward(Constants.BACK);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if (dao != null)
				dao.disConnect();
		}
		return mapping.findForward(Constants.List);

	}
	
	/**
	 * @初始�?
	 */
	public void doINIT(F0407ActionForm actionForm) throws SelectException {
		actionForm.setCurrentPage(1);
	}
}
